home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 653 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.7 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: A.Main@dcs.warwick.ac.uk (Zefram)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Some ideas about C++ and a question
  5. Date: 7 Mar 1996 15:44:48 GMT
  6. Organization: Department of Computer Science, Warwick University, England
  7. Sender: news@dcs.warwick.ac.uk (Network News)
  8. Approved: clamage@eng.sun.com (comp.std.c++)
  9. Message-ID: <1996Mar7.023538.19136@dcs.warwick.ac.uk>
  10. References: <4h9se5$m2n@s3.iway.fr>
  11. NNTP-Posting-Host: taumet.eng.sun.com
  12. X-Nntp-Posting-Host: stone
  13. X-Stardate: [-31]7160.43
  14. X-Us-Congress: Moronic fuckers
  15. Originator: clamage@taumet
  16.  
  17. Valentin Bonnard  <bonnardv@pratique.fr> wrote:
  18. >1) String literals
  19. >~~~~~~~~~~~~~~~~~~
  20. >String literals should be const char* instead of char* (if it is not
  21. >already the case).
  22.  
  23. Actually they're char[], which in practice is almost always decayed to
  24. char*.  The reason they aren't char const[] is that a lot of existing C
  25. code does things like `char *foo="bar";', because const didn't exist in
  26. K&R C.
  27.  
  28. In my opinion, C++ code tends to use const correctly much more than C
  29. code does.  (I personally always write const correctness into my C
  30. code, but a lot of people do not, quite apart from the matter of
  31. existing code.)  It would therefore probably not be disastrous to have
  32. string literals have type char const[] in C++, though it would be in
  33. C.  Maybe in the next round of standardisation?
  34.  
  35. >2) Placement operators
  36. >~~~~~~~~~~~~~~~~~~~~~~
  37. >class Object {
  38. >        void    operator+ // or / or whatever
  39. >                         (Object& result, const Object& b) const;
  40. >        void    operator* (Object& result) const;
  41. >        Object  operator* (const Object& result) const; // old one
  42. >}
  43. >
  44. >should be called respectively by:
  45. >a = b + c;
  46. [...]
  47.  
  48. GCC has a better syntax for this, using a declaration "return result"
  49. between the parameter list and the function body.  The function has a
  50. return value in the usual way, but if it doesn't contain a return
  51. statement with a value then the object in the return declaration is
  52. returned.
  53.  
  54. >4) Conversion of Type** to const Type**
  55. >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  56. >
  57. >It's ok, this is an error; but why cannot Type** be converted to const Type* 
  58. >const* ?
  59.  
  60. It can in C++, but not in C.  It is in fact safe, but the discovery of
  61. the problem with converting T** to T const** led to the present C rule,
  62. which was cast in stone (figuratively) before the C++ rule was
  63. developed.
  64.  
  65. -zefram
  66. -- 
  67. Andrew Main <zefram@dcs.warwick.ac.uk>
  68.  
  69.  
  70. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your
  71.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  72.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  73.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  74.   Comments? mailto:std-c++-request@ncar.ucar.edu
  75. ]
  76.